
#ifndef _TTG_EXTRAS_TTGXMLTREE_
#define _TTG_EXTRAS_TTGXMLTREE_
#include "Common/Definitions.h"

#include "Lexer.h"
#include "Nodes.h"
#include "XMLTree.h"

namespace ttg
{
	namespace extras
	{
		class TTGXMLTree :public XMLTree
		{
			private:
				static const int XML_ERROR = 0;
				static const int END_OF_SECTION = 1;
				static const int ALL_OK = 2;
				int access;
				ttg_internal::SectionNode *root;
				ttg_internal::SectionNode *currentnode;
				ttg_internal::Lexer *lexer;
				int loadNextNode(ttg_internal::SectionNode *node);
				void saveNextNode(ttg_internal::SectionNode *node);
				TTGXMLTree(int access, ttg_internal::SectionNode *root);
				TTGXMLTree(int access, ttg_internal::SectionNode *root, std::list<XMLTree *> *explorers);
			public:
				//control actions
				TTGXMLTree();
				virtual void assign(AccessType access, const char *filename);
				virtual void close();
				virtual XMLTree &getSubXMLTree();
				virtual void resetIterators()
						{ currentnode->resetIterators(); }
				virtual bool openSection(const char *section);
				virtual bool closeSection();
				virtual const char *getCurrentSection();
				virtual size_t getSubSectionCount()
						{ return currentnode->getSections().size(); }
				virtual structures::Dictionary<XMLTree> *getSubSections();
				virtual size_t getAttributeCount()
						{ return currentnode->getAttributes().size(); }
				virtual bool openNextSection();
				//ro actions
				virtual bool getStringAttribute(const char *attr, const char *&val);
				virtual bool getNextAttribute(const char *&attr, const char *&val);
				//wo actions
				virtual void addSection(const char *section);
				virtual void addSectionAndOpen(const char *section);
				virtual void addStringAttribute(const char *attr, const char *val);
				virtual ~TTGXMLTree();
		};
	}
}

#endif
